﻿using Mono.Options;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BookSpider.Common;
using System.Net.Http;

namespace BookSpider
{
    class Program
    {
        static readonly string[] AGENT_LIST = { "" };
        private static HttpClient GetHttpClient()
        {
            Random random = new Random();

            var client = new HttpClient(new HttpClientHandler()
            {
                AllowAutoRedirect = false
            });
            client.DefaultRequestHeaders.Add("UserAgent", AGENT_LIST[random.Next(AGENT_LIST.Length)]);
            client.DefaultRequestHeaders.Add("Referer", "http://www.99lib.net");

            return client;

        }
        static void Main(string[] args)
        {
            var names = new List<string>();
            var bookIdList = new List<string>();
            var pageList = new List<int>();

            var options = new OptionSet {     
                {"k|key=", "",d=>bookIdList.AddRange(d.Explode<string>())},
                {"p|page=","",p=>pageList.AddRange(p.Explode<int>())},
            };
            options.WriteOptionDescriptions(Console.Out);

            List<string> extra;
            try
            {
                extra = options.Parse(args);
                Console.WriteLine(string.Join(",", extra));
                Console.WriteLine(string.Join(",", bookIdList));
                Console.WriteLine(string.Join(",", pageList));
            }
            catch (OptionException e)
            {
                Console.Write("greet: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `greet --help' for more information.");
                return;
            }

            var client = GetHttpClient();
        }
    }
}
